<?php
$alert = "";
if (isset($_REQUEST['dosubmit']) and $_REQUEST['dosubmit'] == 'dosubmit') {

    foreach ($oThis->applications[$appName]['option_sections'] as $option_section) {
        foreach ($option_section['fields'] as $key => $option_field) {
            if (isset($_REQUEST[$key])) {
                update_option($key, $_REQUEST[$key]);
                if (is_array($option_field)) {
                    $label = $option_field[0];
                    $field_type = $option_field[1];
                    if ($field_type == 'checkbox') {
                        update_option($key, 'on');
                    }
                }
            } else {
                if (is_array($option_field)) {
                    $label = $option_field[0];
                    $field_type = $option_field[1];
                    if ($field_type == 'checkbox') {
                        update_option($key, 'off');
                    }
                }
            }
        }
    }
    $alert = 'Settings updated.';
}
?>
<div class="wrap wrpapm">
    <?php
    if (class_exists('MultiPostThumbnails')) {

    } else {
        echo '<div class="well">This class rely on <a href="http://wordpress.org/extend/plugins/multiple-post-thumbnails/" target="_blank">MultiPostThumbnails</a> plugin, please install it</div> ';
    }

    $application = $oThis->applications[$appName];
    ?>

    <h2><?php echo $appLabel . ' - ' . $args['page_type_label']; ?></h2>
    <?php
    $blockid = $appName . '_topintrotext';
    $showintro = get_option('neveragain_' . $blockid . "_" . $current_user->ID);
    if ($appHometext !== '' and $showintro !== 'hide') {
        ?>
        <div class='well wellmedpadd' id="<?php echo $blockid; ?>">
            <?php echo $appHometext; ?>
            <span class="neveragain topintrotext_closealways">&times; Close and never see this anymore?</span>
            <span class="neveragain topintrotext_close">&times; Close</span>
            <span class="clearfix"></span>
        </div>
    <?php } ?>

    <?php if ($alert !== '') { ?>
        <div class='alert'>
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <?php echo $alert; ?>
        </div>
    <?php } ?>

    <ul class="nav nav-tabs" id="myTab">
        <li class="active" ><a href="#modules"data-toggle="tab">Apps & Modules</a></li>
        <li><a href="#settings" data-toggle="tab">Settings</a></li>
        <li><a href="#categories" data-toggle="tab">Categories</a></li>
        <li><a href="#tags" data-toggle="tab">Tags</a></li>

        <?php if (isset($application['show_home_credit']) and $application['show_home_credit'] == true) { ?>
            <li><a href="#about" data-toggle="tab">About this system/plugin</a></li>

        <?php } ?>
    </ul>

    <div class="tab-content">
        <div class="active tab-pane well wellmedpadd" id="modules">
            <h5 class='option_section'>Modules for <?php echo $appLabel; ?></h5>
            <div id="apm_moduleslist" class="apm_settinglist">
                <h6 class=''>Main Modules</h6>
                <?php
                foreach ($oThis->applications[$appName]['modules'] as $k => $module) {
                    if (!isset($module['is_secundary']) or $module['is_secundary'] !== true) {
                        ?>
                        <span class='btn btnmargin apm_homebtnlist'>
                            <?php
                            $icon = '';
                            if (isset($module['icon'])) {
                                $icon = "<img src='" . $apm_settings['paths']['img'] . "/" . $module['icon'] . "' /> ";
                            }
                            ?>
                            <a class='hasTooltip'  title="See all <?php echo $module['name']; ?>" href='admin.php?page=<?php echo $appName . '-' . $k; ?>'> <?php echo $icon . ' ' . $module['name']; ?> </a></br>
                            <a  data-toggle="tooltip"  title="See all <?php echo $module['name']; ?>"  class='hasTooltip' href='admin.php?page=<?php echo $appName . '-' . $k; ?>'> <i class="icon-eye-open "></i> </a>
                            <a   data-toggle="tooltip"  title="Add <?php echo $module['singular_name']; ?>"  class='hasTooltip' href='post-new.php?post_type=<?php echo $k; ?>'> <i class="icon-plus "></i> </a>
                        </span>
                        <?php
                    }
                };
                ?>
                <span class='clearfix'></span>
                <h6 class=''>Other Modules</h6> <?php
                foreach ($oThis->applications[$appName]['modules'] as $k => $module) {
                    if (isset($module['is_secundary']) and $module['is_secundary'] == true) {
                        ?>
                        <span class='btn btnmargin apm_homebtnlist'>
                            <?php
                            $icon = '';
                            if (isset($module['icon'])) {
                                $icon = "<img src='" . $apm_settings['paths']['img'] . "/" . $module['icon'] . "' /> ";
                            }
                            ?>
                            <a class='hasTooltip'  title="See all <?php echo $module['name']; ?>" href='admin.php?page=<?php echo $appName . '-' . $k; ?>'> <?php echo $icon . ' ' . $module['name']; ?> </a></br>
                            <a  data-toggle="tooltip"  title="See all <?php echo $module['name']; ?>"   class='hasTooltip' href='admin.php?page=<?php echo $appName . '-' . $k; ?>'> <i class="icon-eye-open "></i> </a>
                            <a   data-toggle="tooltip"  title="Add <?php echo $module['singular_name']; ?>" class='hasTooltip' href='post-new.php?post_type=<?php echo $k; ?>'> <i class="icon-plus "></i> </a>
                        </span>
                        <?php
                    }
                };
                ?>

                <span class='clearfix'></span>
            </div>
            <h5 class='option_section'>All the Apps</h5>
            <div  class="apm_settinglist">
                <?php
                foreach ($oThis->applications as $k => $app) {
                    if ($app['active']) {
                        $cls = '';
                        if ($app['name'] == $appName) {
                            $cls = 'btn-info';
                        }
                        $tappName = $app['name'];
                        $appsingular_name = $app['singular_name'];
                        $appoptname = get_option($tappName . '_app_name');
                        if ($appoptname !== '' and $appoptname !== false and !empty($appoptname)) {
                            $appsingular_name = $appoptname;
                        }
                        ?>
                        <a  data-toggle="tooltip"  title="Open this App in the same window"  class='btn <?php echo $cls ?> hasTooltip apm_homebtnlist' href='admin.php?page=<?php echo $app['name'] ?>_home'><?php echo $appsingular_name ?></a>
                        <?php
                    }
                };
                ?>

                <span class='clearfix'></span>

            </div>

            <?php if ($oThis->applications["15CRM"]['is_pro'] !== true) { ?>

                <h5 class='option_section'>Latest activities / Dashboard</h5>
                <div  class="apm_settinglist">
                    Will come as an extra feature in the next PRO VERSION of the system. Will list all the latest public activities or activities created by me or shared with me.
                </div>
                <div  class="wellads">FREE VERSION of <a href="" target="_blank">BLUE ORIGAMI CRM</a> <br>To remove ads and get extra features and addons, get the <a href="" target="_blank">PRO VERSION</a>. </div>
            <?php } ?>
        </div>
        <div class="tab-pane well wellmedpadd" id="settings">
            <?php
            if (isset($oThis->applications[$appName]['options_form'])) {
                if (current_user_can('administrator')) {
                    require_once APPLICATION_MAKER_PATH . 'views/' . $oThis->applications[$appName]['options_form'] . '.php'; //apm-home-options
                    //wp_die( __('You do not have sufficient permissions to access this page.') );
                } else {
                    ?>
                    Sorry, the Settings are only available for the Administrator.
                    <?php
                }
            } else {
                ?>
                Sorry, There is not settings for this App.
            <?php }
            ?>
        </div>
        <div class="tab-pane well wellmedpadd" id="categories">
            <?php
            $application = $oThis->applications[$appName];
            if (count($application['categories']) > 0) {
                echo '<ul class="apm_homecategul">';
                foreach ($application['categories'] as $catkey => $category) {
                    //add_submenu_page($key.'-main-menu',$category['name'], 'Category '.$category['menu_name'], 'administrator', $catkey, array($this, 'my_categories_redirect_do'));
                    echo "<li >";
                    // echo "---1 ". $category['menu_name'] ."  -2 ".$catkey."  -3 ".esc_url(add_query_arg(array('taxonomy' => $catkey), 'edit-tags.php'))."  - ";
                    $link = '<a   class="btn btn-small apm_homebtnlist" href="' . esc_url(add_query_arg(array('taxonomy' => $catkey), 'edit-tags.php')) . '"  title="Open the category ' . $category['menu_name'] . '">' . $category['menu_name'] . '</a>';
                    echo $link; //'Manage category '.$category['menu_name'];
                    echo "</li>";
                };
                echo '</ul>';
            }
            ?>
            <span class='clearfix'></span>
        </div>
        <div class="tab-pane well wellmedpadd" id="tags">
            <?php
            if (count($application['tags']) > 0) {
                echo '<ul class="apm_homecategul">';
                foreach ($application['tags'] as $catkey => $category) {
                    //add_submenu_page($key.'-main-menu',$category['name'], 'Category '.$category['menu_name'], 'administrator', $catkey, array($this, 'my_categories_redirect_do'));
                    echo "<li>";
                    // echo "---1 ". $category['menu_name'] ."  -2 ".$catkey."  -3 ".esc_url(add_query_arg(array('taxonomy' => $catkey), 'edit-tags.php'))."  - ";
                    $link = '<a  class="btn btn-small apm_homebtnlist" href="' . esc_url(add_query_arg(array('taxonomy' => $catkey), 'edit-tags.php')) . '"  title="Open the tags ' . $category['menu_name'] . '">' . $category['menu_name'] . '</a>';
                    echo $link; //'Manage category '.$category['menu_name'];
                    echo "</li>";
                };
                echo '</ul>';
            }
            ?>
            <span class='clearfix'></span>
        </div>
        <?php if (isset($application['show_home_credit']) and $application['show_home_credit'] == true) { ?>
            <div class="tab-pane well wellmedpadd" id="about">
                <?php
                require_once APPLICATION_MAKER_VIEWS_PATH . 'application-maker-help.php';
                ?>
            </div>
        <?php } ?>
    </div>
    <?php
// $appIntrotext;
    $categ_list = array();
    /**/